package com.baofu.paycore.biz.enums;

import com.baofu.paycore.common.exception.PayCoreBizException;
import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 命令处理器
 *
 * User: LZQ Date: 2016/04/21  Version: 1.0
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum CommandProcessorEnum {

    BALANCE_PROCESSOR("BALANCE_PROCESSOR","余额处理器"),

    ACC_RECHARGE_PROCESSOR("ACC_RECHARGE_PROCESSOR","账务充值处理器"),

    ACC_FREEZE_PROCESSOR("ACC_FREEZE_PROCESSOR","账务冻结处理器"),

    ACC_UN_FREEZE_PROCESSOR("ACC_UN_FREEZE_PROCESSOR","账务冻结转账处理器"),

    ACC_WITHDRAW_PROCESSOR("ACC_WITHDRAW_PROCESSOR","账务提现处理器"),

    BANK_TRANSFER_PROCESSOR("BANK_TRANSFER_PROCESSOR","银行转账处理器"),

    BANK_PROCESSOR("BANK_PROCESSOR","银行处理器"),

    BANK_CONFIRM_PROCESSOR("BANK_CONFIRM_PROCESSOR","银行确认处理器"),

    BANK_REFUND_PROCESSOR("BANK_REFUND_PROCESSOR","银行退款处理器"),

    BALANCE_REFUND_PROCESSOR("BALANCE_REFUND_PROCESSOR","余额退款处理器"),

    PRE_AUTH_FREEZE_PROCESSOR("PRE_AUTH_FREEZE_PROCESSOR", "预授权冻结处理器"),

    PRE_AUTH_UNFREEZE_PROCESSOR("PRE_AUTH_UNFREEZE_PROCESSOR", "预授权解冻处理器"),

    PRE_AUTH_UNFREEZE_TRANSFER_PROCESSOR("PRE_AUTH_UNFREEZE_TRANSFER_PROCESSOR", "预授权解冻转账处理器"),

    ;

    private String code;

    private String desc;


    public static CommandProcessorEnum getCommandType(String key){
        for (CommandProcessorEnum commandProcessorEnum: values()){
            if(Objects.equals(key, commandProcessorEnum.name())){
                return commandProcessorEnum;
            }
        }
        log.error("支付处理器不支持:{}",key);
        throw new PayCoreBizException(PayCoreErrorCode.UNEXPECTED_ERROR,"支付处理器不支持");
    }
}
